package com.qiang.test07;

public class Foodi implements Runnable {
    @Override
    public void run() {

        while (true) {
            synchronized (Desk.ob) {
                if (Desk.num <= 0) {
                    break;
                } else {
                    //判断是不是有包子

                    if (Desk.flag == true) {
                        System.out.println("吃货在吃汉堡包");
                        Desk.flag = false;

                        //呼叫厨师
                        Desk.ob.notifyAll();

                        //总数减少
                        Desk.num--;
                    } else {

                        //没有包子的话，就等待
                        try {
                            Desk.ob.wait();
                            Desk.ob.notifyAll();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                }
            }
        }
    }
}
